package com.cloudfun.campusshare.schedule;

import com.cloudfun.campusshare.repo.DeviceCsqRepo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * Created by Huqin on 2020/9/28
 */
@Slf4j
@Component
public class DeviceCsqCleanUpSchedule extends BaseScheduleTask {

    @Autowired
    private DeviceCsqRepo deviceCsqRepo;

    /**
     * 每天上午00:15触发
     */
    @Scheduled(cron = "0 15 0 * * ?")
    public void doBalanceAccount() {
        this.execute();
    }

    @Override
    protected String getTaskName() {
        return "设备信号强度记录清理";
    }

    @Override
    protected void doExecute() {
        LocalDateTime tenDaysAgo = LocalDateTime.of(LocalDate.now().plusDays(-10), LocalTime.now());
        int deleteCount = deviceCsqRepo.deleteByCreateTimeLessThan(tenDaysAgo);
        log.info("设备信号强度记录清理完成，清理了：{}条数据", deleteCount);
    }

}
